// pages/withDrawCashRecord/withDrawCashRecord.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pagination: 1,
    records: [],
    end: false,
    name: ['删除作废', '审核失败', '申请中', '审核通过', '付款成功', '付款失败']
  },

  getMoreList() {
    const that = this;
    if (!that.data.end) {
      let json = {
        token: app.globalData.token,
        is_json: 1,
        p: that.data.pagination + 1
      }
      let jsonData = app.utils.getSignData(json);
      app.utils.post(app.api.reqUrls.getWithdrawCashlList, jsonData).then(res => {
        that.setData({
          hiddenLoading: true
        })
        if (res.status == 1) {
          // 格式化时间
          res.result.forEach((item, index) => {
            item.create_time = app.moment(item.create_time*1000).format('YYYY-MM-DD');
            // item.create_time = app.moment(item.create_time).fromNow();
          })
          that.setData({
            records: [...that.data.records, ...res.result]
          })
          // 分页判断
          let len = res.result.length;
          if (len == 0) {
            that.setData({
              end: true
            })
            wx.showToast({
              title: '没有更多了',
              icon: 'none',
              duration: 1000
            })
          } else {
            that.setData({
              pagination: that.data.pagination + 1
            })
          }
        } else {
          throw res.msg
        }
      }).catch(err => {
        app.showInfo(err.toString())
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    let json = {
      token: app.globalData.token,
      type: 'all',
      is_json: 1,
      p: that.data.pagination
    }
    let jsonData = app.utils.getSignData(json);
    app.utils.post(app.api.reqUrls.getWithdrawCashlList, jsonData).then(res => {
      that.setData({
        hiddenLoading: true
      })
      console.log(res)
      if (res.status == 1) {
        // 格式化时间
        res.result.forEach((item, index) => {
          item.create_time = app.moment(item.create_time*1000).format('YYYY-MM-DD');
          // item.create_time = app.moment(item.create_time).fromNow();
        })
        that.setData({
          records: res.result
        })
      } else {
        throw res.msg
      }
    }).catch(err => {
      app.showInfo(err.toString())
    })
  },

})